package com.aoxon.cargo.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.aoxon.cargo.R;
import com.aoxon.cargo.bean.Note;
import com.aoxon.cargo.component.WaterFallShowNote;
import com.aoxon.cargo.shared.NoteShared;
import com.aoxon.cargo.state.MyStateUtil;

/**
 * 采购端便签记录列表
 * 
 * @author ZZJ
 * 
 */
public class PurNoteListActivity extends BaseActivity {

	private ImageView ivReturnButton;
	private ImageView ivAddButton;

	private TextView tvTitle;

	private WaterFallShowNote waterFallShowNote;

	private List<Note> notes = new ArrayList<Note>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setup();
	}

	

	private void setup() {

		setContentView(R.layout.pur_note_list);

		ivReturnButton = (ImageView) findViewById(R.id.ivPublicTitleReturn);
		ivAddButton = (ImageView) findViewById(R.id.ivPublicTitleOther);
		tvTitle = (TextView) findViewById(R.id.tvPublicTiTle);

		ivAddButton.setImageResource(R.drawable.button_yellow_add);
		tvTitle.setText("便签记录");
		
		waterFallShowNote = new WaterFallShowNote(this, 2);

		notes = NoteShared.getNoteList();

		waterFallShowNote.setNoteList(notes);
		waterFallShowNote.addNote();
		
		ivReturnButton.setOnClickListener(myClickListener);
		ivAddButton.setOnClickListener(myClickListener);
		
	}

	
	OnClickListener myClickListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent intent = null;
			switch (v.getId()) {
			case R.id.ivPublicTitleReturn:
				CargoActivity.OPEN_CHOOSE = MyStateUtil.OPEN_MORE;
				intent = new Intent(getBaseContext(), CargoActivity.class);
				startActivity(intent);
				PurNoteListActivity.this.finish();
				break;
			case R.id.ivPublicTitleOther:
				PurNoteInputActivity.isNewAdd = true;
				intent = new Intent(getBaseContext(), PurNoteInputActivity.class);
				startActivity(intent);
				PurNoteListActivity.this.finish();
				break;
			default:
				break;
			}
		}
	};
	
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			CargoActivity.OPEN_CHOOSE = MyStateUtil.OPEN_MORE;
			Intent intent = new Intent(getBaseContext(),
					CargoActivity.class);
			startActivity(intent);
			this.finish();
			return false;
		}
		return false;
	}

	
	
}
